home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / c80tcog.lbr / ENGINT.CQ / engint.c
Text File  |  1985-08-09  |  3KB  |  128 lines

  1. /* engint.c - convert an int to its English equivalent */
  2. /* Version 1.1 1982/11/14 21:56    */
  3.  
  4. /*
  5.  Copyright 1982    William G. Hutchison, Jr.
  6.         P.O. Box 278
  7.         Exton, PA 19341-0278
  8.         USA
  9.  
  10.         CompuServe 70665,1307
  11.  
  12.  
  13.     This  program  may be used freely for any non-commercial
  14. purpose, provided that the user does  not  remove  or  alter
  15. this notice or the copyright statement.
  16.     Those  who  wish  to  sell  or lease this program, or to
  17. incorporate it into a product  for  sale  or  lease,  should
  18. apply to the author (above) for licensing information.
  19.     This  program  is  not  covered  by  a  warranty, either
  20. express or implied. The author shall not be responsible  for
  21. any  damages (including consequential) caused by reliance on
  22. the  materials  presented,  including  but  not  limited  to
  23. typographical errors or arithmetic errors.
  24.  
  25.  */
  26.  
  27. #ifdef MAINLY
  28. #else
  29. #include "c80def.h"
  30. #endif
  31. #ifdef CP_M
  32. extern FILE *STDIN, *STDOUT; 
  33. #endif
  34. #undef trace
  35. #ifdef trace
  36. #include printf.c
  37. #endif
  38.  
  39. char *tens[]= {
  40.     "twenty", "thirty", "forty", "fifty",
  41.     "sixty", "seventy", "eighty", "ninety"};
  42. char *teens[]= {
  43.     "zero", "one", "two", "three", "four",
  44.     "five", "six", "seven", "eight", "nine",
  45.     "ten", "eleven", "twelve", "thirteen",
  46.     "fourteen", "fifteen", "sixteen",
  47.     "seventeen", "eighteen", "nineteen"};
  48.  
  49.  
  50. engint(n) /* convert n to English in ASCII */
  51. int n;
  52. {
  53. _engint(n, 0);
  54. }
  55.  
  56. _engint(n, L)    /* convert n to English in ASCII */
  57. int n;
  58. int L        /* depth of recursion    */;
  59. {
  60. int LL        /* new depth of recursion    */;
  61.  
  62. #ifdef trace
  63. printf("\nn=%7d, level=%7d\n", n, L);
  64. #endif
  65. LL= L+1;
  66. if (n <= -1000 || n >= 1000) {
  67.     _engint(n/1000, LL);
  68.     fputs(" thousand",STDOUT);
  69.     _engint(abs(n % 1000),LL);
  70.     }
  71. else if (n < 0) {
  72.     fputs(" minus",STDOUT);
  73.     _engint(-n, LL);
  74.     }
  75. else if (n >= 100) {
  76.     _engint(n/100, LL);
  77.     fputs(" hundred",STDOUT);
  78.     _engint(n % 100, LL);
  79.     }
  80. else if (n >= 20) {
  81.     fputs(" ",STDOUT);
  82.     fputs(tens[n/10-2],STDOUT);
  83.     _engint(n%10,LL);
  84.     }
  85. else if (n > 0 || L == 0) {
  86.     fputs(" ",STDOUT);
  87.     fputs(teens[n],STDOUT);
  88.     }
  89. }            /* end _engint    */
  90.  
  91. #ifdef MAINLY
  92. #else
  93. /* test driver for engint            */
  94. #ifdef trace
  95. #else
  96. #include "printf.c"
  97. #endif
  98. #define MAINLY
  99. #include "puts.c"
  100. #include "randi1.c"
  101. main() {
  102. int n;
  103. register int seed;
  104. for (n=0; n <= 1000; n++) {
  105.     printf("%7d", n);
  106.     engint(n);
  107.     printf("\n");
  108.     printf("%7d", -n);
  109.     engint(-n);
  110.     printf("\n");
  111.     }
  112. for (n= -32768; n < 0; ) {
  113.     printf("%7d", n);
  114.     engint(n);
  115.     printf("\n");
  116.     printf("%7d", -n);
  117.     engint(-n);
  118.     printf("\n");
  119.     if (n < -1000)
  120.         n+= randi1(&seed)%100;
  121.     else
  122.         n++;
  123.     }
  124. }            /* end main */
  125.  
  126. abs(n){return(n<0? -n:n);}
  127. #endif
  128.